package com.simpou.commons.utils.compiler;

import lombok.AccessLevel;
import lombok.Setter;


/**
 * ClassLoader de compilação.
 *
 * @author Jonas Pereira
 * @since 2011-08-18
 * @version 2012-07-15
 */
final class CompilerClassLoader extends ClassLoader {
    /**
     * Classe Java compilada.
     */
    @Setter(AccessLevel.PACKAGE)
    private CompilerJavaFileObject compiledObj;

    /**
     * <p>Constructor for CompilerClassLoader.</p>
     *
     * @param parentClassLoader ClassLoader.
     */
    CompilerClassLoader(final ClassLoader parentClassLoader) {
        super(parentClassLoader);
    }

    /** {@inheritDoc} */
    @Override
    public Class<?> findClass(final String qualifiedClassName)
        throws ClassNotFoundException {
        byte[] bytes = compiledObj.getBytes();

        return defineClass(qualifiedClassName, bytes, 0, bytes.length);
    }
}
